<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="城市等级" prop="city">
        <el-select v-model="queryParams" placeholder="请选择活动区域">
          <el-option label="一线城市" value="一线城市"></el-option>
          <el-option label="二线城市" value="二线城市"></el-option>
          <el-option label="三线城市" value="三线城市"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="城市" prop="city">
        <el-select v-model="queryParams.city" placeholder="请选择活动区域">
          <el-option
            v-for="item in showdept"
            :key="item.city"
            :label="item.city"
            :value="item.city">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="行政区" prop="registrationTime">

      </el-form-item>
      <el-form-item>
        <div style="display: flex; justify-content: flex-end;">
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </div>
      </el-form-item>

    </el-form>
    <el-collapse v-model="activeName" accordion >
      <el-collapse-item  name="1">
        <template slot="title">
        </template>
        <div>
          <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="auto">
          <el-form-item label="司机证件状态" prop="registrationTime">
            <el-radio-group v-model="queryParams.documentsstatus">
              <el-radio :label="1" >正常</el-radio>
              <el-radio :label="2" >已过期</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="审核人" prop="registrationTime">
            <el-input v-model="queryParams.us" placeholder="请输入审核人" />
          </el-form-item>
          </el-form>
        </div>
      </el-collapse-item>
    </el-collapse>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="注册时间">
        <el-col :span="11">
          <el-date-picker type="date" placeholder="选择日期" v-model="queryParams.registration1" style="width: 100%;"></el-date-picker>
        </el-col>
        <el-col class="line" :span="2">-</el-col>
        <el-col :span="11">
          <el-date-picker placeholder="选择时间" v-model="queryParams.registration2" style="width: 100%;"></el-date-picker>
        </el-col>
      </el-form-item>
      <el-form-item label="审核状态" prop="registrationTime">
        <el-radio-group v-model="queryParams.driverstatus">
          <el-radio :label="0" >未通过</el-radio>
          <el-radio :label="1" >已通过</el-radio>
          <el-radio :label="2" >待审核</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="" prop="registrationTime">
        <el-input v-model="queryParams.mohu" placeholder="请输入姓名，手机号，车牌号查询" >
        </el-input>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:driver:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:driver:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:driver:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:driver:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="driverList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="用户id" align="center" prop="id" fixed/>
      <el-table-column label="司机姓名" align="center" prop="name" fixed/>
      <el-table-column label="司机手机号" align="center" prop="tel"/>
      <el-table-column label="司机头像" align="center" prop="photo" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.photo" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="车牌号" align="center" prop="licensePlateNumber"/>
      <el-table-column label="司机性别" align="center" prop="sex">
        <template slot-scope="scope">
          {{ scope.row.sex == 1 ? '男' : '女' }}
        </template>
      </el-table-column>
      <el-table-column label="司机年龄" align="center" prop="age"/>
      <el-table-column label="生日" align="center" prop="birthday" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="邮箱" align="center" prop="mailbox"/>
      <el-table-column label="驾照有效期" align="center" prop="validity" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.validity, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="注册时所在城市" align="center" prop="city"/>
      <el-table-column label="注册时所在行政区" align="center" prop="administrativeDistrict"/>
      <el-table-column label="最近一次登录时间" align="center" prop=""/>
      <el-table-column label="注册时间" align="center" prop="registration" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.registrationTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="提交审核时间" align="center" prop="submissiontime"/>
      <el-table-column label="审核通过时间" align="center" prop="apporder"/>
      <el-table-column label="审核状态" align="center" prop="driverstatus"/>
      <el-table-column label="审核人" align="center" prop=""/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:driver:remove']"
          >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!--    详情对话框-->
    <el-dialog title="司机及车辆详情" :visible.sync="open" width="1000px" append-to-body>
      <div style="font-size: max(15px, 1vw)">司机信息</div>
      <el-container>
        <el-aside class="el-aside1">
          <image-preview :src="form.photo" :width="250" :height="300"/>
        </el-aside>
        <el-main>
          <el-descriptions size="medium" :title="form.name" direction="horizontal">
            <el-descriptions-item label="性别">{{ form.sex == 1 ? '男' : '女' }}</el-descriptions-item>
            <el-descriptions-item label="生日">{{ form.age }}</el-descriptions-item>
            <el-descriptions-item label="年龄">{{ form.age }}</el-descriptions-item>
            <br>
            <el-descriptions-item label="手机号">{{ form.tel }}</el-descriptions-item>
            <el-descriptions-item label="邮箱">{{ form.mailbox }}</el-descriptions-item>
            <el-descriptions-item label="驾照有效期">{{ form.validity }}</el-descriptions-item>
            <br>
            <el-descriptions-item label="城市">{{ form.city }}</el-descriptions-item>
            <el-descriptions-item label="行政区">{{ form.administrativeDistrict }}</el-descriptions-item>
            <el-descriptions-item label="注册时间">{{ form.registration }}</el-descriptions-item>
          </el-descriptions>
        </el-main>
      </el-container>
      <div style="font-size: max(15px, 1vw)">车辆信息</div>
      <el-container>
        <el-aside class="el-aside2" width="500px">
          <image-preview :src="form.picturesimage" :width="450" :height="400"/>
        </el-aside>
        <el-main>
          <el-descriptions size="medium" title="">
            <el-descriptions-item label="车辆类型：">{{ form.vechicleType }}</el-descriptions-item>
            <el-descriptions-item label="车牌号：">{{ form.licensePlateNumber }}</el-descriptions-item>
            <el-descriptions-item label="车型：">{{ form.vehicleModel }}</el-descriptions-item>
            <el-descriptions-item label="品牌">{{ form.brand }}</el-descriptions-item>
            <el-descriptions-item label="厂家">{{ form.factory }}</el-descriptions-item>
            <el-descriptions-item label="能源类型">{{ form.energyType }}</el-descriptions-item>
            <el-descriptions-item label="发动机号/电动机号">{{ form.engineNumber }}</el-descriptions-item>
            <el-descriptions-item label="车辆VIN码">{{ form.vinNumber }}</el-descriptions-item>
            <el-descriptions-item label="电池容量(KWH)">{{ form.batterycapacity }}</el-descriptions-item>
            <el-descriptions-item label="车龄">{{ form.cheage }}</el-descriptions-item>
            <el-descriptions-item label="CLTC续航里程">{{ form.endurance }}</el-descriptions-item>
            <el-descriptions-item label="电池类型">{{ form.batterytype }}</el-descriptions-item>
          </el-descriptions>
        </el-main>
      </el-container>

      <div style="font-size: max(15px, 1vw)">审核信息</div>
      <el-container>
        <el-aside class="el-aside1" width="220px">
          <image-preview :src="form.driveimg" :width="170" :height="300"/>
        </el-aside>
        <el-aside class="el-aside1" width="220px">
          <image-preview :src="form.steerimg" :width="170" :height="300"/>
        </el-aside>
        <el-aside class="el-aside1" width="220px">
          <image-preview :src="form.inspectimg" :width="170" :height="300"/>
        </el-aside>
        <el-main>
          <el-descriptions size="medium" title="" direction="vertical">
            <el-descriptions-item label="提交审核对象：">{{ }}</el-descriptions-item>
            <el-descriptions-item label="审核状态：">{{ form.carstatus }}</el-descriptions-item>
            <el-descriptions-item label="审核通过时间：">{{ form.approved }}</el-descriptions-item>
            <el-descriptions-item label="审核人">{{ }}</el-descriptions-item>
          </el-descriptions>
        </el-main>
      </el-container>

    </el-dialog>
  </div>
</template>

<script>
import { listDriver, getDriver, delDriver, addDriver, updateDriver } from '@/api/system/driver'
import { listCityRank } from '@/api/cityRank/cityRank'
import { citysel } from '@/api/cityRank/cityRank'

export default {
  name: 'Driver',
  data() {
    return {
      showdept: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 司机信息表格数据
      driverList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        city: null,
        administrativeDistrict: null,
        registrationTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        photo: [
          { required: true, message: '司机头像不能为空', trigger: 'blur' }
        ]
      }

    }
  },
  created() {
    this.getList()
    this.getList1()
  },
  methods: {
    /** 查询司机信息列表 */
    getList() {
      this.loading = true
      listDriver(this.queryParams).then(response => {
        this.driverList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    getList1() {
      citysel().then(res => {
        this.showdept = res.data
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        tel: null,
        photo: null,
        sex: null,
        age: null,
        birthday: null,
        mailbox: null,
        validity: null,
        city: null,
        administrativeDistrict: null,
        registrationTime: null,
        cid: null,
        status: null,
        totalAssets: null,
        monthlyIncome: null,
        currentWithdrawal: null,
        address: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加司机信息'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getDriver(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = '修改司机信息'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDriver(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addDriver(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.open = true
      this.form = row
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/driver/export', {
        ...this.queryParams
      }, `driver_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
